<template>
  <el-dialog :visible='visible' title="名称修改意见"
             @open="openDialog"
             @close="closeDialog">
    <div v-html="'当前名称: ' + name"></div>
    <el-radio-group style="margin-top: 20px; " v-model="radioValue">
      <el-radio style="display: block; height: 40px; " label="editor"
                v-if="UTIL.isNotEmpty(nameSuggestionBak.editorNameSuggestion)">
        <span v-html="'编辑人员: ' + nameSuggestionBak.editorNameSuggestion"/>
        <span v-html="'(' + CONST.NAME_SUGGESTION_STATUS[nameSuggestion.editorStatus] + ')'"/>
      </el-radio>
      <el-radio style="display: block; height: 40px; " label="firstAuditor"
                v-if="UTIL.isNotEmpty(nameSuggestionBak.firstAuditorNameSuggestion)">
        <span v-html="'初审人员: ' + nameSuggestionBak.firstAuditorNameSuggestion"/>
        <span v-html="'(' + CONST.NAME_SUGGESTION_STATUS[nameSuggestion.firstAuditorStatus] + ')'"/>
      </el-radio>
      <el-radio style="display: block; height: 40px; " label="secondAuditor"
                v-if="UTIL.isNotEmpty(nameSuggestionBak.secondAuditorNameSuggestion)">
        <span v-html="'复审人员: ' + nameSuggestionBak.secondAuditorNameSuggestion"/>
        <span v-html="'(' + CONST.NAME_SUGGESTION_STATUS[nameSuggestion.secondAuditorStatus] + ')'"/>
      </el-radio>
      <el-radio style="display: block; height: 40px; " label="thirdAuditor"
                v-if="UTIL.isNotEmpty(nameSuggestionBak.thirdAuditorNameSuggestion)">
        <span v-html="'终审人员: ' + nameSuggestionBak.thirdAuditorNameSuggestion"/>
        <span v-html="'(' + CONST.NAME_SUGGESTION_STATUS[nameSuggestion.thirdAuditorStatus] + ')'"/>
      </el-radio>
    </el-radio-group>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="refuse">拒绝修改</el-button>
      <el-button size="small" type="primary" @click="confirm">确认修改</el-button>
    </div>
  </el-dialog>
</template>

<script>
    export default {
      name: "SolveNameSuggestionDialog",
      props: ['nameSuggestion', 'auditLevel', 'status', 'visible', 'name'],
      data() {
        return {
          radioValue: '',
          nameSuggestionBak: {}
        }
      },
      methods: {
        openDialog() {
          this.nameSuggestionBak = JSON.parse(JSON.stringify(this.nameSuggestion))
          this.radioValue = ''
        },
        closeDialog(){
          this.$emit('update:visible', false)
        },
        refuse(){

          this.$confirm('拒绝所有未处理建议?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            for (let item of ['editor', 'firstAuditor', 'secondAuditor', 'thirdAuditor']) {
              if (UTIL.isNotEmpty(this.nameSuggestionBak[item + 'NameSuggestion']) && this.nameSuggestionBak[item + 'Status'] === 0) {
                this.nameSuggestionBak[item + 'Status'] = 1
              }
            }
            this.$emit('refuse', this.nameSuggestionBak)
          })
        },
        confirm(){
          if (!this.radioValue) {
            this.$message.warning("请选择名称修改意见!")
            return
          }
          for (let item of ['editor', 'firstAuditor', 'secondAuditor', 'thirdAuditor']) {
            if (UTIL.isNotEmpty(this.nameSuggestionBak[item + 'NameSuggestion'])) {
              this.nameSuggestionBak[item + 'Status'] = 1
            }
          }
          let crtName = this.nameSuggestionBak[this.radioValue + 'NameSuggestion']
          this.nameSuggestionBak[this.radioValue + 'Status'] = 2
          this.$emit('confirm', this.nameSuggestionBak, crtName)
        }
      }
    }
</script>

<style scoped>

</style>
